﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Biz_Dal.Biz;

public partial class Admin_Admin_QL_SACH : System.Web.UI.Page
{
    BizKhachHang kh;
    protected void Page_Init(object sender, EventArgs e)
    {
        if (Session["Dang_nhap"] != "1")
        {
            Response.Redirect("~/Trang_web/Trang_chu.aspx");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            //DS_KhachHang.DataSource = new XL_KHACH_HANG();
            //DS_KhachHang.DataBind();
            //ViewState["Mkh"] = "asc";
            //ViewState["Ho_ten"] = "asc";
            //ViewState["Ngay_sinh"] = "asc";
            //ViewState["Dien_thoai"] = "asc";
            //ViewState["Ten_dang_nhap"] = "asc";
            //ViewState["Cotxs"] = "Mkh asc";
        }
    }
    protected void DS_KhachHang_Sorting(object sender, GridViewSortEventArgs e)
    {
        //if (ViewState[e.SortExpression.ToString()].ToString() == "asc")
        //    ViewState[e.SortExpression.ToString()] = "desc";
        //else
        //    ViewState[e.SortExpression.ToString()] = "asc";
        //string caulenh = "select * from khach_hang order by " +
        //   e.SortExpression + " " + ViewState[e.SortExpression.ToString()].ToString();
        //DS_KhachHang.DataSource = new XL_SACH(caulenh);
        //DS_KhachHang.DataBind();
        //ViewState["Cotxs"] = e.SortExpression + " " + ViewState[e.SortExpression.ToString()].ToString();
    
    }
    protected void DS_KhachHang_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //DS_KhachHang.PageIndex = e.NewPageIndex;
        //string caulenh = "select * from khach_hang order by " + ViewState["Cotxs"];
        //DS_KhachHang.DataSource = new XL_SACH(caulenh);
        //DS_KhachHang.DataBind();
    }

    protected void DS_KhachHang_SelectedIndexChanged(object sender, EventArgs e)
    {
        PanelEdit.Visible = true;
        GridViewRow row = DS_KhachHang.SelectedRow;
        int id = Convert.ToInt32(row.Cells[0].Text.ToString());
        // cai id trên này co truyền vào Biz đc ko?
        kh = BizKhachHang.getKhachHangByID(id);
        txtId.Text = id.ToString();
        txtHoTen.Text = kh.hoTen;
        txtTenDN.Text = kh.tenDangNhap;
        txtDiaChi.Text = kh.diaChi;
        txtDienThoai.Text = kh.dienThoai;
        txtEmail.Text = kh.email;
        chkQuanTriVien.Checked = kh.laQuanTri;
        chkBadUser.Checked = kh.laUserXau;
    }
    protected void btnLuu_Click(object sender, EventArgs e)
    {
        //kh = BizKhachHang.getKhachHangByID(Convert.ToInt32(txtId.Text));
        //kh.laQuanTri = chkQuanTriVien.Checked;
        //kh.laUserXau = chkBadUser.Checked;
        //kh.updateKhachHang();
        BizKhachHang.suaUserBad(Convert.ToInt32(txtId.Text), chkBadUser.Checked, chkQuanTriVien.Checked);
        DS_KhachHang.DataBind();

        
    }
}